
const config = require('../config/config')
const mssql = require('mssql')



let query = ( sql, values) => {


  return new Promise(( resolve, reject ) => {
      mssql.connect(config.mssql).then(pool =>  {
            let request = pool.request()
            for(let i=0;i<values.length; ++i){
                request =  request.input(i+1,  values[i])
            }
         
            return request.query(sql);

        }).then(result => {
       
            resolve( result.recordset)
            mssql.close();

        }).catch(error => {
            reject( error )
            mssql.close();

        })

  })
}
module.exports = query;